﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using PassBag;
using PassBag.Logic.RecentFiles;

namespace TestPassBag
{
    [TestFixture, Description("Test recent file list")]
    public class TestRecentFileList {

        [Test, Description ("Test add on empty list")]
        public void AddItemEmptyList()
        {
            RecentFileList list = new RecentFileList();
            string fileName1 = "c:\\file\\hello.tx1";

            list.Add(fileName1);

            Assert.AreEqual (list.Count (), 1);
            Assert.AreEqual (list[0], fileName1);

            list.Clear ();

            Assert.AreEqual (list.Count (), 0);
        }

        [Test, Description ("Test add differenron no empty list")]
        public void AddDifferentItemEmptyList () {
            RecentFileList list = new RecentFileList ();
            string fileName1 = "c:\\file\\hello.tx1";
            string fileName2 = "/file/hello2";
            string fileName3 = "/file/hello3";
            string fileName4 = "/file/hello4";
            string fileName5 = "/file/hello5";

            list.Add (fileName1);
            Assert.AreEqual (list.Count (), 1);
            Assert.AreEqual (list[0], fileName1);

            list.Add (fileName2);
            Assert.AreEqual (list.Count (), 2);
            Assert.AreEqual (list[0], fileName2);

            list.Add (fileName3);
            Assert.AreEqual (list.Count (), 3);
            Assert.AreEqual (list[0], fileName3);

            list.Add (fileName4);
            Assert.AreEqual (list.Count (), 4);
            Assert.AreEqual (list[0], fileName4);

            list.Add (fileName5);
            Assert.AreEqual (list.Count (), 5);
            Assert.AreEqual (list[0], fileName5);
        }

        [Test, Description ("Test add differenrts items to full list")]
        public void AddDifferentItemToFullList () {
            RecentFileList list = new RecentFileList ();
            string fileName1 = "c:\\file\\hello.tx1";
            string fileName2 = "/file/hello2";
            string fileName3 = "/file/hello3";
            string fileName4 = "/file/hello4";
            string fileName5 = "/file/hello5";
            string fileName6 = "/file/hello6";
            string fileName7 = "/file/hello7";

            list.Add (fileName1);
            list.Add (fileName2);
            list.Add (fileName3);
            list.Add (fileName4);
            list.Add (fileName5);

            list.Add (fileName6);
            Assert.AreEqual (list.Count (), 5);
            Assert.AreEqual (list[0], fileName6);
            Assert.AreEqual (list[1], fileName5);
            Assert.AreEqual (list[2], fileName4);
            Assert.AreEqual (list[3], fileName3);
            Assert.AreEqual (list[4], fileName2);

            list.Add (fileName7);
            Assert.AreEqual (list.Count (), 5);
            Assert.AreEqual (list[0], fileName7);
            Assert.AreEqual (list[1], fileName6);
            Assert.AreEqual (list[2], fileName5);
            Assert.AreEqual (list[3], fileName4);
            Assert.AreEqual (list[4], fileName3);
        }

        [Test, Description ("Test add existing items to full list")]
        public void AddExistingItemToFulllList () {
            RecentFileList list = new RecentFileList ();
            string fileName1 = "c:\\file\\hello.tx1";
            string fileName2 = "/file/hello2";
            string fileName3 = "/file/hello3";
            string fileName4 = "/file/hello4";
            string fileName5 = "/file/hello5";

            list.Add (fileName1);
            list.Add (fileName2);
            list.Add (fileName3);
            list.Add (fileName4);
            list.Add (fileName5);

            Assert.AreEqual (list.Count (), 5);

            list.Add (fileName5);

            Assert.AreEqual (list[0], fileName5);
            Assert.AreEqual (list[1], fileName4);
            Assert.AreEqual (list[2], fileName3);
            Assert.AreEqual (list[3], fileName2);
            Assert.AreEqual (list[4], fileName1);

            list.Add (fileName4);
            Assert.AreEqual (list[0], fileName4);
            Assert.AreEqual (list[1], fileName5);
            Assert.AreEqual (list[2], fileName3);
            Assert.AreEqual (list[3], fileName2);
            Assert.AreEqual (list[4], fileName1);
        }

        [Test, Description ("Test add existing items to list")]
        public void AddExistingItemToFList () {
            RecentFileList list = new RecentFileList ();
            string fileName1 = "c:\\file\\hello.tx1";
            string fileName2 = "/file/hello2";
            string fileName3 = "/file/hello3";

            list.Add (fileName3);
            list.Add (fileName2);
            list.Add (fileName1);

            Assert.AreEqual (list.Count (), 3);

            list.Add (fileName3);

            Assert.AreEqual (list[0], fileName3);
            Assert.AreEqual (list[1], fileName2);
            Assert.AreEqual (list[2], fileName1);

            list.Add (fileName2);
            Assert.AreEqual (list.Count (), 3);
            Assert.AreEqual (list[0], fileName2);
            Assert.AreEqual (list[1], fileName3);
            Assert.AreEqual (list[2], fileName1);
        }
    }
}
